package com.tech.service.impl;

import com.tech.mapper.GoodsDao;
import com.tech.mapper.GoodsSortDao;
import com.tech.mapper.factory.DaoImplFactory;
import com.tech.repository.entity.GoodsSort;
import com.tech.service.GoodsSortService;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class GoodsSortServiceImpl implements GoodsSortService {
	private GoodsSortDao goodsSortDao = DaoImplFactory.getGoodsSortDao();
	private GoodsDao goodsDao = DaoImplFactory.getGoodsDao();

	public List<GoodsSort> getLeftSort() {
		// 数据库对应的ID是1
		return goodsSortDao.getChildGoodsSortsBySid(1);
	}

	@Override
	public Map<GoodsSort, List<GoodsSort>> getRightSort() {
		List<GoodsSort> firstSort = goodsSortDao.getAllFirstSort();
		TreeMap<GoodsSort, List<GoodsSort>> map = new TreeMap<>();
		firstSort.forEach(goodsSort -> map.put(goodsSort, goodsSortDao.getChildGoodsSortsBySid(goodsSort.getSid())));
		return map;
	}
}
